<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>Login Page</title>
	{css href="/static/admin/component/pear/css/pear.css"}
	{css href="/static/admin/admin/css/other/login.css"}
</head>
<!-- 代 码 结 构 -->

<body background="/static/admin/admin/images/background2.svg" style="background-size: cover;">
	<form class="layui-form" action="javascript:void(0);">
		<div class="layui-form-item">
			<img class="logo" src="/static/admin/admin/images/logo.png" />
			<div class="title">Task Admin</div>
			<div class="desc">
				最 具 影 响 力 的 设 计 规 范 之 一
			</div>
		</div>
		<div class="layui-form-item">
			<input name="studentNo" value="" placeholder="账 户 :  " hover class="layui-input" />
		</div>
		<div class="layui-form-item">
			<input type="password" value="" name="password" placeholder="密 码 :  " hover class="layui-input" />
		</div>
		<div class="layui-form-item">
			<input placeholder="验证码 : " value="VBJFQ" hover class="code layui-input layui-input-inline" />
			<img src="/static/admin/admin/images/captcha.gif" class="codeImage" />
		</div>
		<div class="layui-form-item">
			<input type="checkbox" name="" title="记住密码" lay-skin="primary" checked>
		</div>
		<div class="layui-form-item">
			<button class="pear-btn pear-btn-success login" lay-submit lay-filter="login">
				登 入
			</button>
		</div>
	</form>
	<!-- 资 源 引 入 -->
	{js href="/static/admin/component/layui/layui.js"}
	{js href="/static/admin/component/pear/pear.js"}

	<script>
		layui.use(['form', 'jquery', 'button', 'popup'], function () {
			var form = layui.form;
			var button = layui.button;
			var popup = layui.popup;
			var $ = layui.jquery;
			// 登 录 提 交
			form.on('submit(login)', function (data) {
				console.log(data);
				// 实例化表单
				var info = new FormData();
				var load = '';
				info.append('password', data.field.password);
				info.append('studentNo', data.field.studentNo);
				$.ajax({
					url: "/api/v1/user/login",
					type: "post",
					dataType: "json",
					contentType: 'application/x-www-form-urlencoded;charset=utf-8',
					data: info,
					contentType: false, //不设置内容类型
					processData: false, //不处理数据
					beforeSend: function () {
						// 加载
						load = button.load({
							elem: '.login',
							done: function () {}
						})
						console.log(load);
					},
					success: function (data) {
						if (data.code == 200) {
							popup.success(data.msg, function () {
								window.location = '/' + data['data'] + '/index';
							});
						} else {
							popup.warming(data.msg, function () {});
						}
						load.stop()
					},
					error: function (XMLResponse) {
						//异常捕获
						// layer.msg(XMLResponse.responseText);
						popup.warming("网络异常", function () {});
					}
				});
				return false;
			});
		})
	</script>
</body>

</html>